package middle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 930. 和相同的二元子数组
 */
public class NumSubarraysWithSum {

    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for (int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] costs = stringToIntegerArray(line);
            line = in.readLine();
            int coins = Integer.parseInt(line);

            int ret = new Solution().numSubarraysWithSum(costs, coins);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }

    static class Solution {
        public int numSubarraysWithSum(int[] nums, int goal) {
            int sum = 0;
            Map<Integer, Integer> cnt = new HashMap<Integer, Integer>();
            int ret = 0;
            for (int num : nums) {
                cnt.put(sum, cnt.getOrDefault(sum, 0) + 1);
                sum += num;
                ret += cnt.getOrDefault(sum - goal, 0);
            }
            return ret;

        }
    }
}
